package com.ocean.productDict.service.impl;

import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.core.text.Convert;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.common.utils.uuid.IdUtils;
import com.ocean.productDict.domain.OFrequency;
import com.ocean.productDict.mapper.OFrequencyMapper;
import com.ocean.productDict.service.IOFrequencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class OFrequencyServiceImpl implements IOFrequencyService
{
    @Autowired
    private OFrequencyMapper oFrequencyMapper;

    /**
     * 查询起报时间维护
     *
     * @param id 起报时间维护主键
     * @return 起报时间维护
     */
    @Override
    public OFrequency selectOFrequencyById(String id)
    {
        return oFrequencyMapper.selectOFrequencyById(id);
    }

    /**
     * 查询起报时间维护列表
     *
     * @param oFrequency 起报时间维护
     * @return 起报时间维护
     */
    @Override
    public List<OFrequency> selectOFrequencyList(OFrequency oFrequency)
    {
        return oFrequencyMapper.selectOFrequencyList(oFrequency);
    }

    /**
     * 新增起报时间维护
     *
     * @param oFrequency 起报时间维护
     * @return 结果
     */
    @Override
    public int insertOFrequency(OFrequency oFrequency)
    {
        oFrequency.setId(IdUtils.simpleUUID());
        SysUser sysUser = ShiroUtils.getSysUser();
        oFrequency.setCreateName(sysUser.getUserName());
        oFrequency.setCreateBy(sysUser.getLoginName());
        oFrequency.setCreateDate(new Date());
        oFrequency.setDepartId(sysUser.getDeptId().toString());
        return oFrequencyMapper.insertOFrequency(oFrequency);
    }

    /**
     * 修改起报时间维护
     *
     * @param oFrequency 起报时间维护
     * @return 结果
     */
    @Override
    public int updateOFrequency(OFrequency oFrequency)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        oFrequency.setUpdateName(sysUser.getUserName());
        oFrequency.setUpdateBy(sysUser.getLoginName());
        oFrequency.setUpdateDate(new Date());
        return oFrequencyMapper.updateOFrequency(oFrequency);
    }

    /**
     * 批量删除起报时间维护
     *
     * @param ids 需要删除的起报时间维护主键
     * @return 结果
     */
    @Override
    public int deleteOFrequencyByIds(String ids)
    {
        return oFrequencyMapper.deleteOFrequencyByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除起报时间维护信息
     *
     * @param id 起报时间维护主键
     * @return 结果
     */
    @Override
    public int deleteOFrequencyById(String id)
    {
        return oFrequencyMapper.deleteOFrequencyById(id);
    }

    @Override
    public Map<String, List> getNameAndCode() {
        Map<String, List> result = new HashMap<>();
        List<OFrequency> list = oFrequencyMapper.selectOFrequencyList(new OFrequency());
        List<String> names = new ArrayList<>();
        List<String> codes = new ArrayList<>();
        for (OFrequency frequency : list) {
            names.add(frequency.getName());
            codes.add(frequency.getCode());
        }
        result.put("names",names);result.put("codes",codes);
        return result;
    }

    @Override
    public OFrequency selectOFrequency(OFrequency oFrequency) {
        return oFrequencyMapper.selectOFrequency(oFrequency);
    }
}
